/*******************************************************************************
 * Copyright (c) 2011 Grupo de Sistemas Inteligentes (GSI) - DIT UPM
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package es.upm.dit.gsi.eclipse.jadex.navigator;

import java.util.Arrays;

import org.eclipse.core.resources.IFile;

/**
 * Class that represents one of the main nodes of the agent file.
 * 
 * @author Pablo Muñoz
 *
 */
public class Child { 
	private IFile container; 
	private String name;  
	private Object[] values;
	
	/**
	 * Constructor for the Child class
	 * @param name name of the node
	 * @param values values of the node
	 * @param file that contains the node
	 */
	public Child(String name, Object[] values, IFile file) { 
		this.name = name;
		this.values = values;
		this.container = file; 
	} 
	
	/**
	 * @return Returns the container.
	 */
	public IFile getContainer() {
		return container;
	}


	/**
	 * @param container The container to set.
	 */
	public void setContainer(IFile container) {
		this.container = container;
	}


	/**
	 * @return Returns the values.
	 */
	public Object[] getValues() {
		return values;
	}


	/**
	 * @param values The values to set.
	 */
	public void setValues(Object[] values) {
		this.values = values;
	}


	/**
	 * @param name The name to set.
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * 
	 * @return the name of the child node
	 */
	public String getName() {
		return name;
	}

	/**
	 * 
	 * @return the value of the child node
	 */
	public SubChild[] getValue() {
		if (values instanceof SubChild[]){
			return (SubChild[]) values;
		}
		else return null;
	}

	/**
	 * 
	 * @return the container of the child node
	 */
	public IFile getFile() { 
		return container;
	}

	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((container == null) ? 0 : container.getName().hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((values == null) ? 0 : Arrays.hashCode(values));
		return result;
	}

	/*
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Child other = (Child) obj;
		if (container == null) {
			if (other.container != null)
				return false;
		} else if (!container.equals(other.container))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (!Arrays.equals(values, other.values))
			return false;
		return true;
	} */
	
	@Override
	public String toString() {
		return getName() + " : " + getValue(); //$NON-NLS-1$
	}


}
